#include<iostream>
#include<iomanip>
using namespace std;
int mouth[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
bool ispy(int year)
{
	if(year%4==0||year%400==0) return true;
	else return false;
}
void getd(int &y,int &m,int &d,int &n)
{
	int yy=y,mm=m,dd=d,nn=n,r;
	if(ispy(yy))
	r=1;
	else
	r=0;
	int i=mm;
	nn-=mouth[r][i]-dd;
	if(nn==0)
	{
		cout<<yy<<" "<<setw(3)<<mm<<" "<<setw(3)<<mouth[r][i]<<endl;
		return ;
	}
	if(nn<0)
	{
		cout<<yy<<" "<<setw(3)<<mm<<" "<<setw(3)<<dd+n<<endl;
		return ;
	}
	while(1)
	{
		i++;
		if(i>12)
		{
			i=1;yy++;
			if(ispy(yy))
			r=1;
			else
			r=0;
		}
		if(nn<=mouth[r][i])
		break;
		nn-=mouth[r][i];
	}
	cout<<yy<<" "<<setw(3)<<i<<" "<<setw(3)<<nn<<endl;
	return ;
}
int main()
{
	int y,m,d,n;
	cin>>y>>m>>d>>n;
	getd(y,m,d,n);
	return 0;
}

